﻿using System;
using System.Collections;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace AdventureWorks.DashboardGroep6.Content
{
    public partial class menu : System.Web.UI.Page
    {
        static ArrayList btn_arr = new ArrayList();

       // static int btn_count = 0;

        private int count = 0;

        protected void Page_Load(object sender, EventArgs e)
        {
            try
            {
                if (btn_arr[0] is Button)
                {
                    //for each button saved in our array, recreate it
                    foreach (Button button in btn_arr)
                    {
                        button.Click += new EventHandler(this.Button1_Click);
                        button.OnClientClick = "Button1_Click";
                        add_button(button);
                    }
                }
            }
            catch (Exception ex)
            {
                //lblStatus.Text += ex.Message.ToString();
            }

        }

        public void setButtons(String[] buttonnames)
        {
            
            foreach (String buttonname in buttonnames)
            {
                Button button = new Button();
                button.Text = buttonname;
                button.Height = 100;
                button.Width = 250;
                button.Enabled = true;
                button.ID = buttonname;         
                btn_arr.Add(button);           
            }
        }

        protected void add_button(Button button)
        {
            try
            {
                //add to a container on the page
                pnlMain.Controls.Add(button);
                //add a spacer after the control
                if (count == 1)
                {
                    pnlMain.Controls.Add(new LiteralControl("<br><br>"));
                    count = 0;
                }
                else
                {
                    pnlMain.Controls.Add(new LiteralControl("&nbsp&nbsp&nbsp&nbsp"));
                    count++;
                }
            }
            catch (Exception ex)
            {
               // lblStatus.Text += ex.Message.ToString();
            }
        }

        protected void Button1_Click(object sender, EventArgs e)
        {

            Button clickedbutton = (Button)sender;
            report report = new report();
            String buttonname = clickedbutton.Text;
            report.setReportService(buttonname);
            Response.Redirect("/content/report.aspx");

        }
    }
}
